#!/bin/sh
if [ $UID -eq 0 ]; then
    echo -e '警告：请勿使用root用户执行此脚本，除非你只有root账户'
    read -p "是否仍要以root身份运行此脚本？<y/n>"
    case $REPLY in
        Y|y)
            echo -e "准备以root身份安装此配置";;
        N|n)
            echo -e "操作取消"
            exit 0;;
        *)
            echo -e "输入错误，操作取消"
            exit 0;;
    esac
fi
sudo pacman -Syu && sudo pacman -S wget picom i3-gaps feh i3status wmctrl
if [ ! -d $HOME/.config/i3/ ]; then
    mkdir -p $HOME/.config/i3
fi
if [ ! -f $HOME/.config/i3/config ]; then
    # 下载配置文件
    touch $HOME/.config/i3/config
    curl -L -o $HOME/.config/i3/config "https://gitee.com/senge-studio/archlinux_plasma_i3wm/raw/master/config"
else
    echo -e '检测到此电脑上存在i3配置文件，正在备份到 $HOME/.config/i3/config.bak'
    cp $HOME/.config/i3/config $HOME/.config/i3/config.bak
    curl -L -o $HOME/.config/i3/config "https://gitee.com/senge-studio/archlinux_plasma_i3wm/raw/master/config"
fi
if [ !-d $HOME/.config/plasma-workspace/env ]; then
    mkdir -p $HOME/.config/plasma-workspace/env
fi
if [ !-d $HOME/.config/wallpapers ]; then
    mkdir -p $HOME/.config/wallpapers
fi
if [ ! -f /usr/bin/i3-switch ]; then
    sudo touch /usr/bin/i3-switch
    sudo curl -L -o /usr/bin/i3-switch "https://gitee.com/senge-studio/archlinux_plasma_i3wm/raw/master/i3-switch"
    sudo chmod 755 /usr/bin/i3-switch
fi
# 
echo "export KDEWM=/usr/bin/i3" > $HOME/.config/plasma-workspace/env/kde-i3.sh
echo -e '已安装成功，请重启电脑'
echo -e '如需设置壁纸，请把壁纸放在$HOME/.config/wallpapers下，并命名为i3wallpaper.png'
echo -e '如果想更换壁纸路径，请手动修改第113行'